<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>select</title>

<link type="text/css" href="css/style.css" rel="stylesheet" />

<script type="text/javascript" src="js/jquery.min.js"></script>
    	
</head>
<body>

<div class="drop">
	<div class="option active placeholder" data-value="placeholder">明智地选择</div>
	<div class="option" data-value="wow" value="1">Wow!</div>
	<div class="option" data-value="drop" value="2">所以放下！</div>
	<div class="option" data-value="select" value="3">非常精选！</div>
	<div class="option" data-value="custom" value="4">很多习俗！</div>
	<div class="option" data-value="animation"> 这样的动画！</div>
</div>

<script type="text/javascript">
$(document).ready(function() {
  $(".drop .option").click(function() {
    var val = $(this).attr("data-value"),
        $drop = $(".drop"),
        prevActive = $(".drop .option.active").attr("data-value"),
        options = $(".drop .option").length;
    $drop.find(".option.active").addClass("mini-hack");
    $drop.toggleClass("visible");
    $drop.removeClass("withBG");
    $(this).css("top");

    $drop.toggleClass("opacity");

    $(".mini-hack").removeClass("mini-hack");

    console.log($(this).text());

    if ($drop.hasClass("visible")) {
      setTimeout(function() {
        $drop.addClass("withBG");
      }, 400 + options*100); 
    }
    triggerAnimation();
    if (val !== "placeholder" || prevActive === "placeholder") {
      $(".drop .option").removeClass("active");
      $(this).addClass("active");
    };
  });
  
  function triggerAnimation() {
    var finalWidth = $(".drop").hasClass("visible") ? 22 : 20;
    $(".drop").css("width", "24em");
    setTimeout(function() {
      $(".drop").css("width", finalWidth + "em");
    }, 400);
  }
});
</script>

</body>
</html>